
if exists (select 1 from sysobjects where name = 'get_personanstellung' and type = 'P')
begin
   drop procedure get_personanstellung
   print 'Procedure: get_personanstellung deleted ...'
end
go
create procedure get_personanstellung(
  @prsid          int           = 3
)
as
begin
  set nocount on
         
  select anstellungid = a.AnstellungID, 
         name = Name, 
         prioritaet = Prioritaet, 
         einsatzprotag = EinsatzProTag, 
         gerechnet = Gerechnet,
         ausgelernt = ausgelernt
    from Anstellung a
   inner join PersonAnstellung pa 
      on pa.AnstellungID = a.AnstellungID
   where Von <= GETDATE() 
     and Bis >= GETDATE() 
     and PrsID = @prsid
   order by Gerechnet

end
go
print 'Procedure: get_personanstellung done ...'
go
grant exec on get_personanstellung to prsadmins with grant option
go
grant exec on get_personanstellung to prsusers
go

